* be truncated, edited, or otherwise trimmed should be done on the
* way to the target.
*/
+#if NEW_STRINGS
+class String {
+ public:
+ String() :
+ s_(NULL) {}
+ bool isEmpty() {
+ return s_ && *s_;
+ }
+ operator char*() const {
+ return s_;
+ }
+ char* operator=(char* s) {
+ s_ = s;
+ return s_;
+ }
+ char* s_;
+};
+#else
+typedef char* String;
+#endif
class waypoint
{
altitude(-99999999.0),
depth(0),
proximity(0),
+#if !NEW_STRINGS
shortname(NULL),
description(NULL),
notes(NULL),
+#endif
route_priority(0),
hdop(0),
vdop(0),
* minimum length for shortname is 6 characters for NMEA units,
* 8 for Magellan and 10 for Vista. These are only guidelines.
*/
- char* shortname;
+ String shortname;
/*
* description is typically a human readable description of the
* waypoint. It may be used as a comment field in some receivers.
* These are probably under 40 bytes, but that's only a guideline.
*/
- char* description;
+ String description;
/*
* notes are relatively long - over 100 characters - prose associated
* with the above. Unlike shortname and description, these are never
* used to compute anything else and are strictly "passed through".
* Few formats support this.
*/
- char* notes;
+ String notes;
/* TODO: UrlLink should probably move to a "real" class of its own.
*/
FILE* xfopen(const char* fname, const char* type, const char* errtxt);
-int case_ignore_strcmp(const char* s1, const char* s2);
-int case_ignore_strncmp(const char* s1, const char* s2, int n);
+// FIXME: case_ignore_strcmp() and case_ignore_strncmp() should probably
+// just be replaced at the call sites. These shims are just here to make
+// them more accomidating of QString input.
+inline int
+case_ignore_strcmp(const QString& s1, const QString& s2) {
+ return QString::compare(s1, s2, Qt::CaseInsensitive);
+}
+// In 95% of the callers, this could be s1.startsWith(s2)...
+inline int case_ignore_strncmp(const QString& s1, const QString& s2, int n) {
+ return s1.left(n).compare(s2, Qt::CaseInsensitive);
+}
+
int str_match(const char* str, const char* match);
int case_ignore_str_match(const char* str, const char* match);
char* strenquote(const char* str, const char quot_char);
#define unknown_alt -99999999.0
#define unknown_color -1
+// TODO: this is a (probably temporary) shim for the C->QString conversion.
+// It's here instead of gps to avoid C/C++ linkage issues.
+int32_t GPS_Lookup_Datum_Index(const QString& n);
+
#endif /* gpsbabel_defs_h_included */
const waypoint* wa = *(waypoint**)a;
const waypoint* wb = *(waypoint**)b;
- return case_ignore_strcmp(wa->shortname, wb->shortname);
+ return case_ignore_strcmp(QString::fromLatin1(wa->shortname), QString::fromLatin1(wb->shortname));
}
return -1;
}
+int32 GPS_Lookup_Datum_Index(const QString& n)
+{
+ return GPS_Lookup_Datum_Index(CSTR(n));
+}
+
const char*
GPS_Math_Get_Datum_Name(const int datum_index)
{
static void
data_read(void)
{
- char* buff;
+ QString buff;
char* s = NULL;
char* trk_name = NULL;
waypoint* wpt_tmp;
int i;
int linecount = 0;
- while ((buff = gbfgetstr(file_in))) {
-
+ while ((buff = gbfgetstr(file_in)), !buff.isNull()) {
if ((linecount++ == 0) && file_in->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
}
* to attempt to divine the data type we are parsing
*/
if (linecount == 1) {
- if (strstr(buff, "Track Point") != NULL) {
+ if (buff.contains("Track Point")) {
trk_head = route_head_alloc();
track_add_head(trk_head);
ozi_objective = trkdata;
- } else if (strstr(buff, "Route File") != NULL) {
+ } else if (buff.contains("Route File")) {
ozi_objective = rtedata;
} else {
ozi_objective = wptdata;
}
} else if (linecount == 2) {
datum = GPS_Lookup_Datum_Index(buff);
+
if (datum < 0) {
- fatal(MYNAME ": Unsupported datum '%s'.\n", buff);
+ fatal(MYNAME ": Unsupported datum '%s'.\n", CSTR(buff));
}
} else if (linecount == 3) {
- if (case_ignore_strncmp(buff, "Altitude is in ", 15) == 0) {
- char* unit = &buff[15];
- if (case_ignore_strncmp(unit, "Feet", 4) == 0) {
+ if (buff.startsWith( "Altitude is in ", Qt::CaseInsensitive)) {
+ QString unit = buff.mid(15);
+ if (unit.startsWith("Feet", Qt::CaseInsensitive)) {
altunit = 'f';
alt_scale = FEET_TO_METERS(1.0);
- } else if (case_ignore_strncmp(unit, "Meter", 5) == 0) {
+ } else if (unit.startsWith("Meter", Qt::CaseInsensitive)) {
altunit = 'm';
alt_scale = 1.0;
} else {
- fatal(MYNAME ": Unknown unit (%s) used by altitude values!\n", unit);
+ fatal(MYNAME ": Unknown unit (%s) used by altitude values!\n", CSTR(unit));
}
}
} else if ((linecount == 5) && (ozi_objective == trkdata)) {
int field = 0;
- s = csv_lineparse(buff, ",", "", linecount);
+ s = csv_lineparse(CSTR(buff), ",", "", linecount);
while (s) {
field ++;
if (field == 4) {
}
}
- if ((strlen(buff)) && (strstr(buff, ",") != NULL)) {
+ if (buff.contains(',')) {
bool ozi_fsdata_used = false;
ozi_fsdata* fsdata = ozi_alloc_fsdata();
wpt_tmp = waypt_new();
/* data delimited by commas, possibly enclosed in quotes. */
- s = buff;
+ s = xstrdup(CSTR(buff));
s = csv_lineparse(s, ",", "", linecount);
i = 0;
9,38.631995,-3.174055,"GC_X",,"Dummy airport (Spain)","Airport",2006/03/28,01:42:01,,"FAC2","CITY2","Canary Island"\r
10,50.493667,12.107150,"Jahnstrasse",,"Jahnstrasse 11","Flag, Red",2006/03/31,21:48:22,,,,\r
11,46.387606,3.498277,"LF_X",,"Dummy airport (France)","Airport",2006/03/28,01:40:32,,"FAC3","CITY3","France"\r
-12,50.493834,12.106100,"Liebknechtstrasse",,"Liebknechtstrasse 90","Waypoint",2006/03/31,21:49:30,,,,\r
-13,43.314550,12.161554,"LI_X",,"Dummy airport (Italy)","Heliport",2006/03/28,01:43:25,,"FAC4","CITY4","Italy"\r
+12,43.314550,12.161554,"LI_X",,"Dummy airport (Italy)","Heliport",2006/03/28,01:43:25,,"FAC4","CITY4","Italy"\r
+13,50.493834,12.106100,"Liebknechtstrasse",,"Liebknechtstrasse 90","Waypoint",2006/03/31,21:49:30,,,,\r
14,50.492616,12.105448,"NARVA",391.0,"Start","Flag, Green",2006/03/31,21:49:26,"http://www.narva-light.de",,,\r
Waypoint GC_X Dummy airport (Spain) Airport N38 37.919719778 W3 10.443304181 Symbol & Name Unknown Airport FAC2 CITY2 Canary Island 28/03/2006 01:42:01 \r
Waypoint Jahnstrasse Jahnstrasse 11 User Waypoint N50 29.619998485 E12 06.429000869 Symbol & Description Unknown Flag, Red 31/03/2006 21:48:22 \r
Waypoint LF_X Dummy airport (France) Airport N46 23.256332763 E3 29.896638617 Symbol & Name Unknown Airport FAC3 CITY3 France 28/03/2006 01:40:32 \r
-Waypoint Liebknechtstrasse Liebknechtstrasse 90 User Waypoint N50 29.630041681 E12 06.366015896 Symbol & Name Unknown Waypoint 31/03/2006 21:49:30 \r
Waypoint LI_X Dummy airport (Italy) Airport N43 18.873018846 E12 09.693240859 Symbol & Name Unknown Heliport FAC4 CITY4 Italy 28/03/2006 01:43:25 \r
+Waypoint Liebknechtstrasse Liebknechtstrasse 90 User Waypoint N50 29.630041681 E12 06.366015896 Symbol & Name Unknown Waypoint 31/03/2006 21:49:30 \r
Waypoint NARVA Start User Waypoint N50 29.556958191 E12 06.326884143 391 m Symbol Unknown Flag, Green 31/03/2006 21:49:26 http://www.narva-light.de Category 15\r
\r
\r
(*ct)++;
}
if (synth && !wpt->shortname) {
+#if NEW_STRINGS
+ char *t;
+ xasprintf(&t, "%s%0*d", namepart, number_digits, *ct);
+ wpt->shortname = t;
+#else
xasprintf(&wpt->shortname,"%s%0*d", namepart, number_digits, *ct);
+#endif
wpt->wpt_flags.shortname_is_synthetic = 1;
}
update_common_traits(wpt);
return buff;
}
-/*
- * Like strcmp, but case insensitive. Like Berkeley's strcasecmp.
- */
-
-int
-case_ignore_strcmp(const char* s1, const char* s2)
-{
- for (; toupper(*s1) == toupper(*s2); ++ s1, ++s2) {
- if (*s1 == 0) {
- return 0;
- }
- }
- return (toupper(*s1) < toupper(*s2)) ? -1 : +1;
-
-}
-
-int
-case_ignore_strncmp(const char* s1, const char* s2, int n)
-{
- int rv = 0;
-
- while (n && ((rv = toupper(*s1) - toupper(*s2)) == 0)
- && *s1) {
- s1++;
- s2++;
- n--;
- }
- return rv;
-}
-
/*
* compare str with match
* match may contain wildcards "*" and "?"
}
if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
- fatal("%s: Invalid latitude %f in waypoint %s.\n",
+ fatal("%s: Invalid latitude %f in waypoint '%s'.\n",
wpt->session->name,
- lat_orig, wpt->shortname ? wpt->shortname : "");
+ lat_orig, wpt->shortname);
if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
- fatal("Invalid longitude %f in waypoint %s.\n",
- lon_orig, wpt->shortname ? wpt->shortname : "");
+ fatal("Invalid longitude %f in waypoint '%s'.\n",
+ lon_orig, wpt->shortname);
/*
* Some input may not have one or more of these types so we
wpt->shortname = xstrdup(wpt->notes);
} else {
/* Last ditch: make up a name */
- xasprintf(&wpt->shortname, "WPT%03d", waypt_ct);
+ char *sn;
+ xasprintf(&sn, "WPT%03d", waypt_ct);
+ wpt->shortname = sn;
}
}
wpt_tmp->altitude = unknown_alt;
wpt_tmp->fix = fix_unknown;
- if (case_ignore_strncmp(ap_wep,"On",2)==0) {
- if (case_ignore_strncmp(ap_type,"AP",2)==0) {
+ QString ap_wep_(ap_wep);
+ QString ap_type_(ap_type);
+ if (ap_wep_.startsWith("on", Qt::CaseInsensitive)) {
+ if (ap_type_.startsWith("AP", Qt::CaseInsensitive)) {
wpt_tmp->icon_descr = aicicon; /* Infra Closed */
} else {
wpt_tmp->icon_descr = ahcicon; /* AdHoc Closed */
}
} else {
- if (case_ignore_strncmp(ap_type,"AP",2)==0) {
+ if (ap_type_.startsWith("AP", Qt::CaseInsensitive)) {
wpt_tmp->icon_descr = aioicon; /* Infra Open */
} else {
wpt_tmp->icon_descr = ahoicon; /* AdHoc Open */
xol_waypt_disp_cb(const waypoint* wpt)
{
double x, y;
- char* name;
+ const char* name;
name = wpt->shortname;
if ((name == NULL) || (*name == '\0') || global_opts.synthesize_shortnames) {